library(dplyr)
library(ggplot2)
library(rriskDistributions)
library(haven)
generate_non_normal_beta_dist = function(n,q_vect,min,max){
  # y = a + bx, when x=min,y=0; when x=max,y=1
  # x = (y-a)/b
  b = 1/(max-min)
  a = -b*min
  q_vect_normalized = q_vect * b + a
  rst = get.beta.par(q=q_vect_normalized)
  beta_dist = rbeta(n,rst[1],rst[2])
  beta_dist_non_normalized = (beta_dist-a)/b
  return(beta_dist_non_normalized)
}

v1 = generate_non_normal_beta_dist(1000,c(2,11,12),0,20)
v2 = generate_non_normal_beta_dist(1000,c(2,3,12),0,20)

grp = c(rep(1,15),rep(2,18))
exe_time = c(sample(v1,15),sample(v2,18))

df = data.frame(grp=grp,exe_time=round(exe_time))
write_sav(df,'./data/ch07_1.2_data.sav')
